<template>
    <div class="app-container" v-loading.fullscreen.lock="fullLoading">

        <el-form :model="queryParams" ref="queryForm" size="mini" :inline="true" label-width="68px">
            <el-form-item label="学号" prop="stuNo">
                <el-input v-model="queryParams.stuNo" placeholder="请输入学号" clearable @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="学生姓名" prop="stuName">
                <el-input v-model="queryParams.stuName" placeholder="请输入学生姓名" clearable @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label=" ">
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-table v-loading="loading" :data="table_data">
            <el-table-column label="学生" prop="stuName" align="center" />
            <el-table-column label="学号" prop="stuNo" align="center" />
            <el-table-column label="班级" prop="className" align="center" />
            <el-table-column label="申请时间" prop="createTime" align="center">
                <template slot-scope="scope">
                    {{ dayjs(scope.row.createTime).format("YYYY-MM-DD HH:mm:ss") }}
                </template>
            </el-table-column>
            <el-table-column label="申请状态" align="center">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.audius_detail_type" :value="scope.row.applyStatus" />
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center">
                <template slot-scope="scope">
                    <el-button v-if="scope.row.applyStatus == 1" type="text" size="mini" icon="el-icon-view"
                        @click="auditVClick(scope.row)">审核</el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
            @pagination="getList" />


        <el-dialog title="申请" :visible.sync="auditV" fullscreen :append-to-body="true">
            <el-form class="detail" label-width="160px">
                <el-row>
                    <div style="display: flex;">
                        <el-col :span="12" style="margin-right: 50px;">
                            <el-form-item label="班级">
                                <el-input readonly size="mini" v-model="auditForm.className"
                                    class="auditForm-input"></el-input>
                            </el-form-item>
                            <el-form-item label="姓名">
                                <el-input readonly size="mini" v-model="auditForm.stuName"
                                    class="auditForm-input"></el-input>
                            </el-form-item>

                            <el-form-item label="政治面貌">
                                <el-input readonly size="mini" class="auditForm-input" v-model="auditForm.zzmm"></el-input>
                            </el-form-item>

                            <el-form-item label="青年大学习学习率">
                                <el-input readonly size="mini" class="auditForm-input"
                                    v-model="auditForm.youthStudy"></el-input>
                            </el-form-item>
                            <el-form-item label="第二课堂学分认定">
                                <el-input readonly size="mini" class="auditForm-input"
                                    v-model="auditForm.classTwo"></el-input>
                            </el-form-item>

                            <el-form-item label="职务">
                                <el-input readonly size="mini" class="auditForm-input"
                                    v-model="auditForm.classPost"></el-input>
                            </el-form-item>
                            <el-form-item label="获奖情况">
                                <el-input readonly type="textarea" :maxlength="1000"
                                    :autosize="{ minRows: 10, maxRows: 10 }" class="auditForm-input"
                                    v-model="auditForm.goodHis"></el-input>
                            </el-form-item>
                            <el-form-item label="主要事迹">
                                <el-input readonly type="textarea" :maxlength="1000"
                                    :autosize="{ minRows: 10, maxRows: 10 }" class="auditForm-input"
                                    v-model="auditForm.mainHis"></el-input>
                            </el-form-item>
                            <el-form-item label="您的审核意见">
                                <el-row>
                                    <el-col :span="12">
                                        <el-select @change="changeAuditStatus" placeholder="请选择审核意见" style="width: 200px;"
                                            v-model="doForm.applyStatus" size="mini">
                                            <el-option v-for="(v, i) in status_list" :key="i" :label="v.label"
                                                :value="v.value">
                                            </el-option>
                                        </el-select>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-button @click="doAudit" type="success" size="mini">提交审核</el-button>
                                    </el-col>

                                </el-row>

                                <el-input placeholder="请输入审核意见" type="textarea" :maxlength="1000"
                                    :autosize="{ minRows: 10, maxRows: 10 }" class="auditForm-input"
                                    v-model="doForm.fdyCmt"></el-input>
                            </el-form-item>
                        </el-col>


                        <el-col :span="12">
                            <div>
                                <el-row>
                                    <el-col :span="4">
                                        <span style="font-weight: bolder;">该生申请奖项:</span>
                                    </el-col>
                                    <el-col :span="8">
                                        <span style="color: red; font-weight: bolder;">
                                            优秀毕业生
                                        </span>
                                    </el-col>
                                    <el-col :span="6">
                                        <el-button type="primary" @click="lookNeedV = true;" size="mini">查看评优要求</el-button>
                                    </el-col>
                                </el-row>
                            </div>


                            <el-drawer :modal="false" size="50%" title="评优要求" :visible.sync="lookNeedV" direction="ltr"
                                :append-to-body="true">
                                <div class="sign">
                                    <ol>
                                        <li>
                                            德、智、体、美、劳全面发展，在校期间未受纪律处分。
                                        </li>
                                        <li>
                                            学习勤奋，成绩优异，第一学期至第五学期所有课程的平均学分绩专业排名前10%。
                                        </li>
                                        <li>
                                            积极参加学校开展的第二课堂活动活动，第二课堂成绩单学分认定为优秀。身体健康，体能考核成绩达标。(每学年体测成绩60分以上)
                                        </li>
                                        <li>
                                            获得过校级及以上“三好学生”“优秀学生干部”“优秀共青团员”“优秀共青团干部”中的其中一项荣誉。
                                        </li>
                                        <li>
                                            积极参与各级各类校园文化活动和社会实践活动;在各级各类活动(竞赛)中成绩突出;六个学期青年大学习率达98%以上;在就业创业方面作为优秀典型。
                                        </li>
                                        <li>
                                            同等条件下，获得国家奖学金或国家励志奖学金等国家级奖励的毕业生应优先推荐。
                                        </li>
                                        <li>
                                            认定为校级优秀毕业生，才有资格推荐为上级优秀毕业生。
                                        </li>
                                    </ol>
                                </div>
                            </el-drawer>


                            <el-table :data="rank_data">
                                <el-table-column label="学业成绩专业排名" align="center">
                                    <template slot-scope="scope">
                                        {{ scope.row.majorRank + "/" + scope.row.majorCount }}
                                    </template>
                                </el-table-column>
                                <el-table-column label="专业排名百分比(四舍五入保留整数)" align="center">
                                    <template slot-scope="scope">
                                        {{ Math.round(Math.round(scope.row.majorRank / scope.row.majorCount * 10000) / 100)
                                            + "%" }}
                                    </template>
                                </el-table-column>
                            </el-table>
                            <el-table :data="sport_data">
                                <el-table-column label="学年" align="center" prop="stuYearName" />
                                <el-table-column label="体测成绩" align="center" prop="sportScore" />
                            </el-table>

                        </el-col>
                    </div>


                </el-row>
            </el-form>

        </el-dialog>

        <el-dialog :visible.sync="lookMoreV" :append-to-body="true">
            <MoreDetail></MoreDetail>
        </el-dialog>


    </div>
</template>
<script>
import { listOwnClass } from "@/api/stuCQS/info-fill/stu_eva_task";
import { listEnableYear as listYear } from "@/api/stuCQS/basedata/year";
import { listSelect } from "@/api/stuCQS/lake/type";

import {
    listFdy, fdyAudit, getStuScoreMajorRank, listStuSportScore
} from "@/api/comprehensive/biyeapply";

import {
    applyStatus
} from "@/api/stuCQS/good/audit";

import { isEmpty, groupBy } from "@/api/helpFunc";
import MoreDetail from '@/views/stuCQS/lake/MoreDetail.vue';
import dayjs from "dayjs";


export default {
    name: "lakefdy",
    dicts: ['audius_detail_type'],
    components: {
        MoreDetail
    },
    data() {
        return {
            dayjs,
            applyStatus,
            search_type_list: [],

            isEmpty,

            fullLoading: false,

            loading: false,
            table_data: [],
            total: 0,
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                code: null,
                status: null,
                stuNo: "",
                stuName: ""
            },

            auditV: false,
            auditForm: {},

            myScoreV: false,


            doForm: {
                id: null,
                applyStatus: null,
                fdyCmt: "同意申请"
            },

            class_list: [],
            year_list: [],

            lookNeedV: false,
            lookMoreV: false,

            status_list: [
                {
                    label: "通过",
                    value: 2
                },
                {
                    label: "驳回(学生可以重新提交)",
                    value: 10
                },
                {
                    label: "拒绝(学生不可以再提交)",
                    value: 11
                }
            ],

            rank_data: [],
            sport_data: []

        }
    },
    created() {
        this.listSelect();
        this.listOwnClass();
        this.listAllStuYear();
        this.getList();
    },
    methods: {
        changeAuditStatus(v) {
            switch (v) {
                case 2:
                    this.doForm.fdyCmt = "同意申请。";
                    break;
                case 10:
                    this.doForm.fdyCmt = "填写有误，请重新提交。";
                    break;
                case 11:
                    this.doForm.fdyCmt = "拒绝申请。";
                    break;
                default:
                    this.doForm.fdyCmt = "同意申请。";
                    break;
            }
        },
        async listSelect() {
            let res = await listSelect();
            if (res.code == 200) {
                this.search_type_list = [...res.data];
            }
        },
        lookMore() {
            this.lookMoreV = true;
            window.open('http://zhxg.gxsdxy.cn/file/jhzx2023.pdf');
        },
        async listAllStuYear() {
            let res = await listYear();
            if (res.code == 200) {
                this.year_list = [...res.rows];
            }
        },
        async listOwnClass() {
            let res = await listOwnClass();
            if (res.code == 200) {
                this.class_list = [...res.data];
            }
        },
        async getList() {
            this.loading = true;
            let res = await listFdy(this.queryParams);
            this.loading = false;
            if (res.code == 200) {
                this.table_data = [...res.rows];
                this.total = res.total;
            }
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        async auditVClick(v) {
            this.auditForm = { ...v };
            this.auditV = true;
            this.getStuScoreMajorRank(v.stuNo);
            this.listStuSportScore(v.stuNo);
        },
        async getStuScoreMajorRank(stuNo) {
            let res = await getStuScoreMajorRank(stuNo);
            if (res.code == 200) {
                this.rank_data = [res.data];
            }
        },
        async listStuSportScore(stuNo) {
            let res = await listStuSportScore(stuNo);
            if (res.code == 200) {
                this.sport_data = [...res.data];
            }
        },

        async doAudit() {
            let sdata = { ...this.doForm };
            if (isEmpty(sdata.applyStatus)) {
                this.$message.info("请选择是否通过");
                return;
            }
            if (isEmpty(sdata.fdyCmt)) {
                this.$message.info("请填写审核意见");
                return;
            }
            sdata.id = parseInt(this.auditForm.id);
            this.fullLoading = true;
            let res = await fdyAudit(sdata);
            this.fullLoading = false;
            if (res.code == 200) {
                this.getList();
                this.auditForm = {};
                this.doForm = {
                    id: null,
                    applyStatus: null,
                    fdyCmt: "同意申请"
                };
                this.auditV = false;
                this.$message.success(res.msg);
            }
        }
    }
}
</script>
<style lang="scss" scoped>
.addForm-input {
    width: 400px;
}

.detail {
    .el-form-item {
        margin-bottom: 0px;
    }
}

.sign {
    width: 100%;
    border: 1px solid rgb(163, 211, 255);
    font-size: small;
    margin-bottom: 10px;
    border-radius: 2px;
}
</style>